package top.syfy.jwt.jwtdemo.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.syfy.jwt.jwtdemo.interceptor.LoginInterceptor;

/**
 * SpringMVC 的补充配置
 *
 * @author syfy
 * @date 2021/03/05
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

	/**
	 * 向容器中添加登录拦截器
	 *
	 * @return 登录拦截器实例
	 */
	@Bean
	public LoginInterceptor loginInterceptor() {
		return new LoginInterceptor();
	}

	/**
	 * 添加拦截器规则
	 *
	 * @param registry 拦截器注册器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry
			.addInterceptor(loginInterceptor())
			.addPathPatterns("/**")
			.excludePathPatterns(
				"/sys/login",
				"/sys/logout",
				"/static/**"
			);
	}
}
